/*
Init.sqf
Author: Craig Vander Galien 
Email: craigvandergalien@gmail.com
ModDB: http://www.moddb.com/mods/bobtoms-arma2-missions
Armaholic: http://www.armaholic.com/page.php?id=15778
BIS forums: http://forums.bistudio.com/showthread.php?128781-TvT-FFA-CO-40-Dynamic-Zombie-Sandbox

Any questions? Contact me at one of the above places.

Thanks,
Craig
*/

//Include Strings for text like side missions.
#include "en_strings.sqf";

// ====================================================================================
// DEFINES
	#ifndef execNow
	#define execNow call compile preprocessfilelinenumbers
	#endif
	#define PP preprocessfilelinenumbers
	#define VAR_DEFAULT(var,val) if (isNil #var) then {var=(val);}
// ====================================================================================	
// init persistentDB
		execNow "core\init.sqf";
// ====================================================================================


sleep 5;

[] execVM "WEFRAG\init_functions.sqf";

//Just some variables being set for if is server, client, jip. 
if(isServer) then { Z_Server = true;} else { Z_Server = false;};
if(!isDedicated) then { Z_Client = true; } else { Z_Client = false};
if(isNull player) then { Z_JIP = true; } else { Z_JIP = false; };

//Init some variables
screendone = 0;
paramsDone = 0;
trigArray = [];

//If jip client.. Execute some JIP code.
if(Z_JIP) then { [] execVM "onJip.sqf"; };


gameType = (paramsArray select 9);

if (gameType == 0) then {
    //Launch the mission
    [] execVM "craigs_scripts\startup.sqf";

    waitUntil {screendone == 1};

    /*
	if(Z_Server) then {
	"R3F_DZS" addPublicVariableEventHandler {[_this select 1] execVM "server_obj_spawn.sqf"};
	};
	*/

    // sets parameter defaults if the game is in SP
    if (isNil "paramsArray") then {
        CLY_friendlyfire= 2;
        CLY_terraingrid= 0;
        CVG_debug= 1;
        CVG_timeToSkipTo = 26;
        CVG_CityDestruction= 1;
        CVG_bandages=2;
        CVG_Fog = 1;
        CVG_Viewdist = 300;
        CVG_Weather = 1;
        gameType = 0;
        CVG_playerWeapons = 1; 
        CVG_playerItems= 1; 
        CVG_Aminals= 1; 
        CVG_horde= 1;
        CVG_maxaggroradius=400;
        CVG_Zdensity = 50;
        CVG_minSpawnDist = 50;
        CVG_weapontype= 1;
        CVG_Zombietowns= 2;
        CVG_taskType = 1;
        CVG_taskoption = 0;
        vehspawntype=0;
        chanceNumber = 10;
        CVG_Fuel = 1;
        CVG_FastTime = 1;
        CVG_Weaponcount  = 1;
        CVG_VehicleStatus = 4;
        CVG_Respawn = 1;
        CVG_backpacks = 1;
        CVG_Caches = 1;
        CVG_survivors = 0;
        CVG_logistics = 1;
        WF_Modif = 1;
    };


    if (CVG_logistics == 1) then {
        [] execVM "R3F_ARTY_AND_LOG\init.sqf";
    };
        
    //randomSafePos script by Spam_One (not using right now) ------------------------------------------
    //[]execVM "randomSafePos.sqf";

    //spawns raiders
    if (isServer) then {
        if (CVG_survivors == 1) then {
            [] execVM "craigs_scripts\raidersOn.sqf";
        };
		
        if (CVG_SideMissions == 1) then {
            SMarray = ["SM1","SM3","SM4","SM5","SM6","SM7","SM8"];
            [1] execVM "sideMissions\SMfinder.sqf";
        };	
    };
};



if (gameType == 1) then {
    [] execVM "gamemodes\LTJ_infected\infected_startUp.sqf";
};

//launch celery's scripts

[] execVM  "craigs_scripts\zombiesinit.sqf";
[] exec "craigs_scripts\zombiesinit.sqs";

	
//init keypress get-in system
if (!isdedicated) then {
    waitUntil {!isNil "CVG_E"};
    if (CVG_E == 1) then {
	onKeyPress = compile preprocessFile "craigs_scripts\onKeyPress.sqf";
	waitUntil {!(IsNull (findDisplay 46))};
	(findDisplay 46) displayAddEventHandler ["KeyDown", "nul = [_this select 0, _this select 1] execVM 'craigs_scripts\onKeyPress.sqf' "];
    };
};


//runs player connect script
onPlayerConnected "Z_JIP_Time = date; publicVariable ""Z_JIP_Time""";

sleep 5;
_messages = ["Escape this hellhole!","Survive","Lock and load","Get ready, Zombies are coming","Pillage and steal","The higher, the better","Enjoy your stay!","Headshots are better!!","craigvandergalien@gmail.com","Unite or Fight","Kill some Zs!","By Craig Vander Galien","Help: Luke Jansen"];


// words at start, dedicated can't run it
if (!isDedicated) then {
    _pos = (getPosATL player);
    _words = _messages call BIS_fnc_selectRandom;
    waitUntil {_pos distance (getPosATL player) > .1};
    [str ("DZS:Dynamic Zombie Sandbox") ,  str (format ["%1", name player]),_words] spawn BIS_fnc_infoText;
};

if ((gameType == 0) and (WF_Modif == 1)) then	 {
    [] execVM "WEFRAG\init.sqf";
};


